package code.tools.commponents
{
	import code.structure.manager.loader.DllLoaderManager;
	import code.structure.manager.font.FontManager;
	import code.structure.manager.language.LanguageManager;
	import code.untils.FiltersEnum;
	import code.untils.UiNameConst;
	
	import com.greensock.plugins.AutoAlphaPlugin;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class TextFieldItem extends Component
	{
		private static const TEXT_SELECTED_COLOR:uint = 0x77681E;
		private static const TEXT_NORMAL_COLOR:uint = 0xffffff;
		public var _textField:TextField;
		private var _selectedImg:Sprite;
		private var _subType:int;
		private var _clickHandler:Function;
		/** 脚注Icon  */
		private var _footnodeIcon:Sprite;
		function TextFieldItem(parent:DisplayObjectContainer,xpos:Number,ypos:Number,subType:int,clickHandler:Function)
		{
			_subType = subType;
			_clickHandler = clickHandler;
			super(parent,xpos,ypos);
			addEventListener(MouseEvent.CLICK,mouseClickHandler);
			addEventListener(MouseEvent.ROLL_OVER,hoverHandler);
		}
		
		override protected function init():void
		{
			setSize(160,18);
			super.init();
		}
		
		override protected function addChildren():void
		{
			graphics.beginFill(0,0);
			graphics.drawRect(0,0,_width,_height);
			graphics.endFill();
			
			super.addChildren();
			buttonMode = true;
			_selectedImg = new (DllLoaderManager.getInstance().getMaterial(UiNameConst.PANEL_VIEW,'textFieldItem_selected')as Class)as Sprite;
			_selectedImg.y = 1;
			addChild(_selectedImg);
			_textField = Helpers.FormatTextField(this,11,0,147,TextFieldAutoSize.LEFT,TEXT_NORMAL_COLOR,FontManager.getInstance().embeddedFontBName,15);
			(_textField as AutoTextField).openZoom(147,20);
			_textField.mouseEnabled = false;
			/** 脚注Icon  */
			_footnodeIcon = new (DllLoaderManager.getInstance().getMaterial(UiNameConst.PANEL_VIEW,'footnodeIcon')as Class)as Sprite;
			Helpers.processTf(_footnodeIcon,'new_text',LanguageManager.getLanguageInfo('TITLE_NEW'),FontManager.getInstance().embeddedFontCName,true,true);
			_footnodeIcon.x = _width - _footnodeIcon.width - 8;
			_footnodeIcon.y = (_selectedImg.height - _footnodeIcon.height)*.5 + 1;
			_footnodeIcon.visible = false;
			addChild(_footnodeIcon);
			draw();
		}
		
		override public function draw():void
		{
			if(hover || selected)
			{
				_textField.textColor = TEXT_SELECTED_COLOR;
				_selectedImg.visible = true;
				_textField.filters = [FiltersEnum.TREE_TEXT_SELECTED_OR_HOVER_DROPSHADOWFILTER];
			}
			else
			{
				_textField.textColor = TEXT_NORMAL_COLOR;
				_selectedImg.visible = false;
				_textField.filters = [FiltersEnum.TREE_TEXT_NORMAL_DROPSHADOWFILTER];
			}
		}
		
		private function hoverHandler(e:MouseEvent):void
		{
			hover = true;
			addEventListener(MouseEvent.ROLL_OUT,outHandler);
		}
		
		private function outHandler(e:MouseEvent):void
		{
			hover = false;
			removeEventListener(MouseEvent.ROLL_OUT,outHandler);
		}
		
		private function mouseClickHandler(e:MouseEvent):void
		{
			selected = true;
			_clickHandler(this);
		}
		
		private var _text:String;
		public function get text():String
		{
			return _text;
		}
		
		public function set text(value:String):void
		{
			_text = value;
			_textField.text = value;
		}
		
		private var _selected:Boolean;
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function set selected(value:Boolean):void
		{
			_selected = value;
			draw();
		}
		
		private var _hover:Boolean;
		
		public function get hover():Boolean
		{
			return _hover;
		}
		
		public function set hover(value:Boolean):void
		{
			_hover = value;
			draw();
		}
		
		public function get subType():int
		{
			return _subType;
		}
		/**
		 *设置是否显示脚注icon 
		 * @param value
		 * 
		 */
		public function set isShowFootnodeIcon(value:int):void
		{
			_footnodeIcon.visible = value > 0;
		}
	}
}